<!--# layout("/common/layout.html",{"jsBase":"/js/templateapp/templateApp/"}){ -->

<form class="layui-form layui-form-pane" id="addForm" enctype="multipart/form-data"  lay-filter="editform">
    <input type="hidden" id="templateType" name="templateType" value="${templateType}">
    <input type="hidden" id="linkId" name="linkId" value="${linkId}">
    <br>
    <div class="layui-row" id="templateIdDiv" style="display:none;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">模板Id</label>
                <div class="layui-input-inline" style="">
                    <input type="text" name="templateId" id="templateId" autocomplete="off" class="layui-input" readonly>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">模板名称</label>
				<div class="layui-input-inline" style="width: 500px;">
                                <input type="text" name="templateName" id="templateName" autocomplete="off" class="layui-input" lay-verify="required">
				</div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">标题</label>
				<div class="layui-input-inline" style="width: 500px;">
                                <input type="text" name="templateTitle" id="templateTitle" autocomplete="off" class="layui-input" lay-verify="required">
				</div>
            </div>
        </div><!--form item-->
    </div><!--row-->

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">跳转页面</label>
                <div class="layui-input-inline" style="width: 500px;">
                    <input type="text" name="returnPage" id="returnPage" autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <layui:image id="templateImg" tagName="图片" tips="图片说明"/>
        </div>
    </div>


    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script>
    Common.initImage();
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','templateAppApi'], function(exports) {
    var form = layui.form;
    var templateAppApi = layui.templateAppApi;
    var index = layui.index;
    var isNew = true;
    <!--# if(!(isEmpty(templateAppJson))){  -->
    isNew = false;
    $("#templateIdDiv").attr("style","display:block;");
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                form.on('submit(form)', function(){
                    templateAppApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(templateAppJson))){  -->
    var formJson = ${templateAppJson};
    form.val("editform",formJson);
    $(".image-preview").each(function() {
        $(this).attr("src",formJson[$(this).attr("id")]);
    });
    <!--# } -->
});
</script>
